<template>
  <div class="login-page">
    <div id="Login" class="login-container">
      <el-form :model="patient" label-width="80px">
        <h1 style="padding-bottom: 30px;">
          患者注册
        </h1>
        <el-form-item label="姓名" prop="name" required>
          <el-input v-model="patient.patientName" placeholder="请输入姓名" size="large"/>
        </el-form-item>
        <el-form-item label="登录账号" prop="username" required>
          <el-input v-model="patient.patientUsername" placeholder="请输入登录账号" size="large"/>
        </el-form-item>
        <el-form-item label="密码" prop="password" required>
          <el-input type="password" v-model="patient.patientPassword" placeholder="请输入密码" size="large"/>
        </el-form-item>
        <el-form-item label="性别" prop="patientSex" required>
          <el-radio-group v-model="patient.patientSex">
            <el-radio value="1" size="large">男</el-radio>
            <el-radio value="2" size="large">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="身份证" prop="patientIdnum" required>
          <el-input v-model="patient.patientIdnum" placeholder="请输入身份证" size="large"/>
        </el-form-item>
        <el-form-item label="医保号" prop="medicalInum" required>
          <el-input v-model="patient.medicalInum" placeholder="请输入医保号码" size="large"/>
        </el-form-item>
        <el-form-item label="电话" prop="patientPhone" required>
          <el-input v-model="patient.patientPhone" placeholder="请输入电话号码" size="large"/>
        </el-form-item>
        <el-form-item label="住址" prop="patientAddress" required>
          <el-input v-model="patient.patientAddress" placeholder="请输入住址" size="large"/>
        </el-form-item>
        <el-form-item label="" style="margin-bottom: 0;margin-left: 120px">
          <el-link :underline="false" href="/login">已有账户？立即登录</el-link>
        </el-form-item>
        <el-form-item style="padding-left: 40px;padding-top: 10px;">
          <el-button type="primary" @click="register" size="large">注册</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {register} from "@/api/pat.js";
import {ElMessage, ElNotification} from "element-plus";

export default {
  name: "register",
  data() {
    return {
      patient: {
        patientSex: '1'
      }
    }
  },
  methods: {
    async register() {
      try {
        const response = await register(this.patient);
        if (response.data.code == 200) {
          ElNotification({
            title: '成功！',
            message: "注册成功",
            type: 'success',
          });
          this.$router.push("/login")
        } else {
          ElNotification({
            title: '失败！',
            message: response.data.msg,
            type: 'warning',
          });
        }
      } catch (e) {
        ElNotification({
          title: '失败！',
          message: "请输入全部信息后重试",
          type: 'error',
        });
      }
    },

  }
}
</script>

<style scoped>
.login-page {
  background-image: url("/a.jpg");
  background-size: cover;
  display: flex;
  align-items: center;
  justify-content: center; /* 水平居中 */
  min-height: 100vh; /* 垂直居中 */
}

.login-container {
  width: 450px;
  height: 640px;
  margin: 0 auto;
  text-align: center;
  padding: 10px;
  background: #f0f2f5; /* 设置登录容器的背景色 */
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* 添加阴影效果 */
  display: flex;
  flex-direction: column; /* 垂直居中时，容器内部内容垂直排列 */
  justify-content: center; /* 内部元素垂直居中 */
  align-items: center; /* 内部元素水平居中 */
}
</style>
